package com.itheima.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * @author wz
 * @description:
 * @date 2021-10-31
 */
// 指定当前类为spring的配置类
@Configuration
// 开启ioc注入的扫描
@ComponentScan(basePackages = {"com.itheima"})
//加载properties的资源,spring会将配置文件的数据加入ioc容器，供其他bean引用
@PropertySource(value = {"classpath:data.properties"},encoding = "UTF-8")
public class SpringConfig {

    @Bean("dataSource")
    public DataSource dataSource() {

        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setPassword("1234");
        return dataSource;
    }

}
